﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Animation;
using MapLibrary.Players;
using Microsoft.Xna.Framework;
using MapLibrary.Particles.Emitters;

namespace MapLibrary.Enemies
{
    public class ExplodeableObject : Sprite
    {
        private const string ExplodeableInitConds = "ExplodeableInitConds";
        private TriggeredParticleEmitter emitter;

        public ExplodeableObject()
        {
            Explodeable = true;
        }

        public void Explode()
        {
            emitter = new TriggeredEmitterFromData(World.ParticleManager,
                this,
                ExplodeableInitConds);
            World.CurrentLevel.AddBodyToRemove(this);
            emitter.Trigger();
        }

        public override void Update()
        {
            base.Update();
            Body.IsStatic = true;
        }

        public override bool MyOnCollision(FarseerPhysics.Dynamics.Fixture f1, FarseerPhysics.Dynamics.Fixture f2, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            Player p = f2.Body.UserData as Player;
            if (p != null)
            {
                Vector2 vel = p.Body.LinearVelocity;
                if (vel.Y > 0)
                {
                    p.NumberJumps = 0;
                    p.EnterStateWithProperDirection("Landing");
                }
            }

            return true;
        }
    }
}
